package kingiis.utils.trysvg.pages;

import android.content.Intent;
import android.os.Message;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.MotionEvent;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.Switch;

import butterknife.InjectView;
import butterknife.OnClick;
import kingiis.utils.simpleapp.BAct;
import kingiis.utils.simpleapp.anno.Layout;
import kingiis.utils.simpleapp.anno.Vertical;
import kingiis.utils.simpleapp.listener.AppBarStateChangeListener;
import kingiis.utils.simpleapp.utils.Log;
import kingiis.utils.simpleapp.view.refreshview.RefreshExtra;
import kingiis.utils.simpleapp.view.refreshview.RefreshLayout;
import kingiis.utils.trysvg.R;
import kingiis.utils.trysvg.adapter.MainAI;
import kingiis.utils.trysvg.handlers.MyHandler;
import kingiis.utils.trysvg.kot.OneAct;

@Vertical
@Layout(R.layout.act_main)
public class MainActivity extends BAct {

    @InjectView(R.id.content)
    CoordinatorLayout content;
    @InjectView(R.id.toolbar)
    Toolbar toolbar;
    @InjectView(R.id.appBar)
    AppBarLayout appBar;
    @InjectView(R.id.refresh)
    RefreshLayout refresh;
    @InjectView(R.id.recycler)
    RecyclerView recycler;

    @Override
    public void initView() {
        init();
    }

    @Override
    public void initListener() {

    }

    @Override
    public android.os.Handler onFinish() {
        return null;
    }


    MainAI adapter;
    LinearLayoutManager recyclerManager;
    AppBarStateChangeListener appBarListener;

    private void init() {
        recyclerManager = new LinearLayoutManager(context);
        recycler.setLayoutManager(recyclerManager);
        adapter = new MainAI(new String[]{"1", "2", "3", "4", "5", "6"});
        recycler.setAdapter(adapter);
        appBarListener = new AppBarStateChangeListener() {
            @Override
            public void onStateChanged(AppBarLayout appBarLayout, State state, int offset) {
                boolean stateSwitch = false;
                switch (state) {
                    case EXPANDED:
                        Log.i("1");
                        stateSwitch = true;
                        refresh.setEnableOverScroll(stateSwitch);
                        refresh.setOverScrollRefreshShow(stateSwitch);
                        refresh.setEnableRefresh(stateSwitch);
                        refresh.setEnableLoadmore(stateSwitch);
                        refresh.setBottomHeight(120);
                        refresh.setHeaderHeight(120);
                        RefreshExtra.add(refresh, context);
                        break;
                    case COLLAPSED:
                        Log.i("2");
                        stateSwitch = false;
                        refresh.setEnableOverScroll(stateSwitch);
                        refresh.setOverScrollRefreshShow(stateSwitch);
                        refresh.setEnableRefresh(stateSwitch);
                        refresh.setEnableLoadmore(stateSwitch);
                        refresh.setBottomHeight(0);
                        refresh.setHeaderHeight(0);
                        break;
                    default:
                        break;
                }
            }
        };
        appBar.addOnOffsetChangedListener(appBarListener);

    }


}
